/**
 * Created by iallai on 2/1/2018.
 */

import axios from 'axios'
import {CONFIG} from '@/config/env'

let API=CONFIG.PROJECT.API;
const queryNew = (query={}) => new Promise((resolve, reject) => {

  query.is_follow_up=0;
  query.is_new=1;

  //query.give_back_times=0;

  axios.get(`${API.URL}/admin_threads`,{
    params:query
  }).then(function(res){
      if(API.isOK(res.data)){
        resolve(res.data);
      }
    })
    .catch(function(err){
      reject("网络错误");
    });



});
const query = (query={}) => new Promise((resolve, reject) => {

  query.is_follow_up=0;
  query.is_new=0;
  axios.get(`${API.URL}/admin_threads`,{
    params:query
  }).then(function(res){
      if(API.isOK(res.data)){
        resolve(res.data);
      }
    })
    .catch(function(err){
      reject("网络错误");
    });



});
const delAll = (query={}) => new Promise((resolve, reject) => {
    console.log("删除")


});
const get = (data) => new Promise((resolve, reject) => {


  axios.get(`${API.URL}/admin_threads/${data.id}`,{
    params:data
  }).then(function(res){
      if(API.isOK(res.data)){
        resolve(res.data);
      }
    })
    .catch(function(err){
      reject("网络错误");
  });



});

const update = (query={}) => new Promise((resolve, reject) => {


  axios.get(`${API.URL}/load_register`,{
    params:query
  }).then(function(res){
      if(API.isOK(res.data)){
        resolve(res.data);
      }else {
        reject("获取认证信息错误");

      }
    })
    .catch(function(err){
      reject("获取认证信息错误");
    });



});
const add = (query={}) => new Promise((resolve, reject) => {


  axios.get(`${API.URL}/load_register`,{
    params:query
  }).then(function(res){
      if(API.isOK(res.data)){
        resolve(res.data);
      }else {
        reject("获取认证信息错误");

      }
    })
    .catch(function(err){
      reject("获取认证信息错误");
    });



});
const close = (query={}) => new Promise((resolve, reject) => {


  axios({
    method: 'post',
    url: `${API.URL}/admin_threads/close`,
    params:query,

  }).then(function(res){
    if(API.isOK(res.data)){
      resolve(res.data);
    }else{
      reject(res.data.message);
    }
  }).catch(function(err){
    reject("网络错误");
  });



});
const assign = (query={}) => new Promise((resolve, reject) => {

  axios({
    method: 'post',
    url: `${API.URL}/admin_threads/assign`,
    params:query,

  }).then(function(res){
    if(API.isOK(res.data)){
      resolve(res.data);
    }else{
      reject(res.data.message);
    }
  }).catch(function(err){
    reject("网络错误");
  });


});
const _levelToText = function (value) {

  switch (value) {
    case 'none':
      return '无意向';
      break;
    case 'low':
      return '随便问问';
      break;
    case 'middle':
      return '考虑中';
      break;
    case 'high':
      return '高意向';
      break;
  }
}

export {get,query,queryNew,assign,update,add,close,delAll,_levelToText}

